Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
unc-path-regex
Advanced tools
Regular expression for testing if a file path is a windows UNC file path. Can also be used as a component of another regexp via the `.source` property.
The unc-path-regex npm package provides a regular expression specifically designed to match UNC (Universal Naming Convention) paths. UNC paths are used to specify the location of resources like files or devices on a network. This package is particularly useful for developers working with network file systems in Node.js applications, allowing them to validate and manipulate UNC paths efficiently.
UNC Path Validation
This feature allows developers to validate if a given string is a UNC path. The provided code sample demonstrates how to use the unc-path-regex to test if specific paths are UNC paths.
const uncPathRegex = require('unc-path-regex');
const regex = uncPathRegex();
console.log(regex.test('\\\\Server01\\user\\docs\\Letter.txt')); // true
console.log(regex.test('C:\\path\\to\\file.txt')); // false
Extract UNC Path Components
This feature can be used to extract components of a UNC path using the regex match method. The code sample shows how to extract the full UNC path from a string.
const uncPathRegex = require('unc-path-regex');
const regex = uncPathRegex();
const uncPath = '\\\\Server01\\share\\file.txt';
const match = uncPath.match(regex);
console.log(match[0]); // '\\\\Server01\\share\\file.txt'
The path-regex package provides a regular expression to match and validate general file paths. Unlike unc-path-regex, which is specialized for UNC paths, path-regex handles a broader range of file paths including both Windows and POSIX formats.
is-unc-path is a package that checks if a path is a UNC path. It provides a more focused approach similar to unc-path-regex but instead of providing a regex, it offers a function that returns a boolean indicating whether the path is a UNC path or not.
Regular expression for testing if a file path is a windows UNC file path. Can also be used as a component of another regexp via the
.source
property.
Visit the MSDN reference for Common Data Types 2.2.57 UNC for more information about UNC paths.
Install with npm
$ npm i unc-path-regex --save
// unc-path-regex returns a function
var regex = require('unc-path-regex')();
true
Returns true for windows UNC paths:
regex.test('\\/foo/bar');
regex.test('\\\\foo/bar');
regex.test('\\\\foo\\admin$');
regex.test('\\\\foo\\admin$\\system32');
regex.test('\\\\foo\\temp');
regex.test('\\\\/foo/bar');
regex.test('\\\\\\/foo/bar');
false
Returns false for non-UNC paths:
regex.test('/foo/bar');
regex.test('/');
regex.test('/foo');
regex.test('/foo/');
regex.test('c:');
regex.test('c:.');
regex.test('c:./');
regex.test('c:./file');
regex.test('c:/');
regex.test('c:/file');
.git/
true
if the given string looks like a glob pattern.Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on July 07, 2015.
FAQs
Regular expression for testing if a file path is a windows UNC file path. Can also be used as a component of another regexp via the `.source` property.
The npm package unc-path-regex receives a total of 5,590,284 weekly downloads. As such, unc-path-regex popularity was classified as popular.
We found that unc-path-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.